package com.multithread.base.impl;

import com.multithread.base.Queue;

/**
 * @author: hfxiang
 * @Description:
 * @date: 2022/8/9 13:57
 */
public class QueueBlock extends Queue {
    public QueueBlock(Integer size) {
        super(size);
    }

    public void purchase() {
        synchronized(this){
            if (isFull()){
                System.out.println("队列满满满满满满满满满满满满了田田田田田田田田田田田田田田田田田田田田");
                try {
                    wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }else {
                putIn();
                notifyAll();
            }
        }
    }

    public void sale() {
        synchronized(this){
            if (isEmpty()){
                System.out.println("队列满满满满满满满满满满满满了田田田田田田田田田田田田田田田田田田田田");
                try {
                    wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }else {
                putOut();
                notifyAll();
            }
        }
    }
}
